package com.sc.nft.entity;

import java.io.Serializable;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sc.nft.enums.AllowedShoppingCouponsEnum;
import com.sc.nft.enums.ApprovalStatusEnum;
import com.sc.nft.enums.MallChannelEnum;
import com.sc.nft.enums.ProductTypeEnum;
import com.sc.nft.exception.GlobalRunTimeException;
import com.sc.nft.sup.SuperEntity;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * IP商城商品表(sc_mall_product)实体类
 *
 * @author zxy
 * @since 2023-05-10 16:59:01
 * @description IP商城
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@TableName("sc_mall_product")
public class MallProduct extends SuperEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 商品类型
     */
    private ProductTypeEnum type;
    /**
     * 分类Id
     */
    private Long categoryId;
    /**
     * DAOId
     */
    private Long daoId;
    /**
     * 封面图
     */
    private String coverImage;
    /**
     * 缩略图
     */
    private String thumbnail;
    /**
     * 商品编码
     */
    private String productCode;
    /**
     * 商品渠道
     */
    private MallChannelEnum productChannel;
    /**
     * 商品标题
     */
    private String productName;
    /**
     * 商品详情
     */
    private String productDetail;
    /**
     * 审批状态
     */
    private ApprovalStatusEnum approvalStatus;
    /**
     * 审核备注
     */
    private String remark;

    private Boolean isLongImage;

    /**
     * 商品属性ID
     */
    private Long attributeId;

    /**
     * 是否为虚拟商品
     */
    private Boolean isVirtual;

    /**
     * 是否允许使用购物金
     *
     */
    private boolean isAllowedShoppingCoupons;

    /**
     * 添加商品
     */
    public MallProduct addPassProduct(Long daoId, String productName, String coverImage, String thumbnail, String productDetail, Long categoryId, ProductTypeEnum type, Boolean isLongImage,Long attributeId) {
        isLongImage = ObjectUtil.isNull(isLongImage) ? Boolean.FALSE : isLongImage;
        this.daoId = daoId;
        this.productCode = IdUtil.getSnowflakeNextIdStr();
        this.productName = productName;
        this.coverImage = coverImage;
        this.thumbnail = thumbnail;
        this.productDetail = productDetail;
        this.approvalStatus = ApprovalStatusEnum.PASS;
        this.categoryId = categoryId;
        this.type = type;
        this.isLongImage = isLongImage;
        this.attributeId = attributeId;
        this.isVirtual = true;
        this.insert();
        return this;
    }

    /**
     * 编辑商品
     */
    public MallProduct editPassProduct(String productName, String coverImage, String thumbnail, String productDetail, Long categoryId, ProductTypeEnum type,Long attributeId) {
        this.productName = productName;
        this.approvalStatus = ApprovalStatusEnum.PASS;
        this.coverImage = coverImage;
        this.thumbnail = thumbnail;
        this.productDetail = productDetail;
        this.categoryId = categoryId;
        this.type = type;
        this.attributeId = attributeId;
        this.updateById();
        return this;
    }

}